<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //求数组里所有值的和  跟平均值
        /* var a = [11,22,33,44,55,66,77,88,99,1010]
        var c = 0
        for ( b = 0; b < a.length; b++ ) {
            c = c +a[b]
        }
        console.log(c);
        console.log(c/a.length); */


        //取最大值
       /*  var a = [11,22,33,44,55,66,77,88,99,1010]
        var max = a[0]
        for (i = 0; i<a.length;i++) {
            if (max<a[i]) {
                max = a[i]
            }
        }
        console.log(max); */

        //从前往后取
        /* var a = ['貂蝉','吕布','张飞','刘备']
        var b = ''
        for (i = 0; i < a.length; i++) {
            if (i !== a.length-1) {
                b = b + a[i] + '-'
            }else {
                b += a[i]
            }
        }
        console.log(b); */


        //从后往前取
        var a = ['貂蝉','吕布','张飞','刘备']
        var b = ''
        for (i=a.length-1;i>=0;i--) {
            if (i !== 0) {
                b = b + a[i] + '-'
            }else {
                b = b + a[i] 
            }
        }
        console.log(b);
    </script>
</body>
</html>